package com.faithnmn.learnenglishbc.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.faithnmn.learnenglishbc.R;
import com.faithnmn.learnenglishbc.listener.ChangeFragmentListener;
import com.faithnmn.learnenglishbc.service.LessionsPlayer;

public class SeriesFragment extends Fragment implements OnClickListener{
	private ChangeFragmentListener changeFragmentListener;
	
	public void setChangeFragmentListener(ChangeFragmentListener changeFragmentListener){
		this.changeFragmentListener  = changeFragmentListener;
	}
	
@Override
public View onCreateView(LayoutInflater inflater,@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
	View series = inflater.inflate(R.layout.fragment_series, null);
	TextView seri1 = (TextView) series.findViewById(R.id.series1);
	TextView seri2 = (TextView) series.findViewById(R.id.series2);
	TextView seri3 = (TextView) series.findViewById(R.id.series3);
	TextView seri4 = (TextView) series.findViewById(R.id.series4);
	ImageView playing1= (ImageView)series.findViewById(R.id.playings1);
	ImageView playing2= (ImageView)series.findViewById(R.id.playings2);
	ImageView playing3= (ImageView)series.findViewById(R.id.playings3);
	ImageView playing4= (ImageView)series.findViewById(R.id.playings4);
	int currentSeriIndex = LessionsPlayer.currentSeriIndex;
	if(LessionsPlayer.getMediaplayer() != null){
		if(currentSeriIndex == 0){
			playing1.setVisibility(View.VISIBLE);
		}else if(currentSeriIndex == 1){
			playing2.setVisibility(View.VISIBLE);
		}else if(currentSeriIndex == 2){
			playing3.setVisibility(View.VISIBLE);
		}else if(currentSeriIndex == 3){
			playing4.setVisibility(View.VISIBLE);
		}
	}
	seri1.setOnClickListener(this);
	seri2.setOnClickListener(this);
	seri3.setOnClickListener(this);
	seri4.setOnClickListener(this);
	return series;
}

@Override
public void onClick(View v) {
		switch (v.getId()) {
		case R.id.series1:
			if(changeFragmentListener != null){
				SeriFragment seriFragment = SeriFragment.getInstance(0, "Series 1");
				seriFragment.setChangeFragmentListener(changeFragmentListener);
				changeFragmentListener.onDisplayFragment(seriFragment, seriFragment.getClass().getName());
			}
			break;
		case R.id.series2:
			if(changeFragmentListener != null){
				SeriFragment seriFragment = SeriFragment.getInstance(1, "Series 2");
				seriFragment.setChangeFragmentListener(changeFragmentListener);
				changeFragmentListener.onDisplayFragment(seriFragment, seriFragment.getClass().getName());
			}
			break;
		case R.id.series3:
			if(changeFragmentListener != null){
				SeriFragment seriFragment = SeriFragment.getInstance(2, "Series 3");
				seriFragment.setChangeFragmentListener(changeFragmentListener);
				changeFragmentListener.onDisplayFragment(seriFragment, seriFragment.getClass().getName());
			}
			break;
		case R.id.series4:
			if(changeFragmentListener != null){
				SeriFragment seriFragment = SeriFragment.getInstance(3, "Series 4");
				seriFragment.setChangeFragmentListener(changeFragmentListener);
				changeFragmentListener.onDisplayFragment(seriFragment, seriFragment.getClass().getName());
			}
			break;
		default:
			break;
		}
	}
}
